<?php 
$sheng = array();
$city = array();
$bases = array();

$city = MtsysCity::model()->find('CITY_ID=:CID',array(
	':CID' => $countys->CITY_ID
));
$sheng = MtsysProvince::model()->find('PROVINCE_ID=:PID',array(
	':PID' => $city->PROVINCE_ID
));
$bases = MtsysBase::model()->findAll('COUNTY_ID=:AID',array(
	':AID' => $countys->COUNTY_ID
));
$county = $countys;

if(empty($sheng)){
	echo '<span style="color:red">单位不存在，请联系上级管理员</span>';
	return;	
}

?>
<div id="page-unit">
<ul>
	<li>
	<span class="collapse" id="PROVINCE_<?php echo $sheng->PROVINCE_ID;?>"><?php echo $sheng->PROVINCE_NAME;?></span>
    <ul data-super-id="PROVINCE_<?php echo $sheng->PROVINCE_ID;?>">
        <li>
		<span class="collapse" id="CITY_<?php echo $city->CITY_ID;?>"><?php echo $city->CITY_NAME;?></span> 
        <ul data-super-id="CITY_<?php echo $city->CITY_ID;?>">
			<li>
			<span class="collapse" id="COUNTY_<?php echo $county->COUNTY_ID;?>">
			<?php echo $county->COUNTY_NAME;?>
            </span>
            <em class="info_user">（<?php echo MtsysCounty::model()->getUser($county->COUNTY_ID);?>）</em>
            
            <a href="#" onclick='$("#base_create").attr("src","/index.php?r=mtsysBase/create&p=<?php echo $sheng->PROVINCE_ID;?>&c=<?php echo $city->CITY_ID;?>&a=<?php echo $county->COUNTY_ID;?>");$("#base").dialog("open"); return false;' data-type="BASE" data-id="<?php echo $sheng->PROVINCE_ID.'|'.$city->CITY_ID.'|'.$county->COUNTY_ID;?>">添加站点</a>
            <a href="javascript:void(0);" class="unit_admin edit" data-op="edit" data-type="COUNTY" data-id="<?php echo $county->COUNTY_ID;?>">修改</a>
            <a href="javascript:void(0);" class="unit_admin delete" data-op="delete" data-type="COUNTY" data-id="<?php echo $county->COUNTY_ID;?>">删除</a>
	
            <?php if(!empty($bases)){ ?>
            <ul  data-super-id="COUNTY_<?php echo $county->COUNTY_ID;?>">
            	<?php foreach($bases as $base){?>
            	<li><span id="BASE_<?php echo $base->BASE_ID;?>">
					<?php echo $base->BASE_NAME; ?>
                    </span>
                    <em class="info_user">（<?php echo MtsysBase::model()->getUser($base->BASE_ID);?>）</em>
                    <a href="javascript:void(0);" class="unit_admin edit" data-op="edit" data-type="BASE" data-id="<?php echo $base->BASE_ID;?>">修改</a>
            <a href="javascript:void(0);" class="unit_admin delete" data-op="delete" data-type="BASE" data-id="<?php echo $base->BASE_ID;?>">删除</a>
                <?php } ?>
            </ul>
            <?php }?>
            </li>
        </ul>       
        </li>
    </ul>
    </li>
</ul>
</div>

<?php 
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'unit',
    'options'=>array(
        'title'=>'新增单位',
        'autoOpen'=>false,
    ),
));
?>
<div class="form unit">
	<div class="grey inline">	
    <label>
        <label>上级单位:</label>
        <input type="text" name="unit_super_name" value="" />
        <input type="hidden" name="unit_super_id" value="" />
    </label>
    <label>
        <label>单位级别:</label>
        <input type="hidden" name="unit_type" value="" />
        <input type="text" name="unit_type_name" value="" />
    </label>
    <label>
        <label>单位名称:</label>
        <input type="text" name="unit_name" value="" />    
    </label>
    <input type="button" name="commit" value="提交" class="button blue"/>
    <input type="hidden" name="oper" value="" />
    </div>
</div>
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
Yii::app()->clientScript->registerScriptFile('js/pager.unit.js', CClientScript::POS_END);
?>


<?php 
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'base',
    'options'=>array(
        'title'=>'新增站点',
		'width'=>'480',
        'autoOpen'=>false,
    ),
));
?>
<div class="form unit">
<iframe src="/index.php?r=mtsysBase/create&p=<?php echo $sheng->PROVINCE_ID;?>&c=<?php echo $city->CITY_ID;?>&a=<?php echo $county->COUNTY_ID;?>" width="450" height="200" frameborder="0" scrolling="no"></iframe>
</div>
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<script>
function baseDialogClose(){
	window.location.href = window.location.href;	
}
</script>